|
|
|
|
|
|
|
Figure 28.5
To set up the ADO Data control at
designtime, use its Property Pages. |
|
|
|
|
|
|
|
|
The Property Pages dialog box for the ADO Data control is divided into the following tabs: |
|
|
|
|
|
|
|
|
General. Specifies how the ADO Data control connects to the database. |
|
|
|
|
|
|
|
|
Authentication. Allows you to supply a username and password that the ADO Data control can use to connect to the database, if required. |
|
|
|
|
|
|
|
|
RecordSource. Defines what recordset the ADO Data control retrieves from the data source. Here, you can specify a table or stored procedure name, or an SQL query. |
|
|
|
|
|
|
|
|
Color and Font. Change the look of the ADO Data control. |
|
|
|
|
|
|
|
|
Many of the options in these tabs can also be set from code. By setting the appropriate properties, you can link the ADO Data control to your database and use data-bound controls on your form to display the data. |
|
|
|
|
|
|
|
|
Connecting the ADO Data Control to a Data Source |
|
|
|
|
|
|
|
|
You already know that databases are made up of multiple tables and can contain a great deal of data. For example, the BIBLIO database includes one table that contains author information and another that contains a list of books written by those authors. When you think about working with data in a Visual Basic program, you generally do not plan to use every record in the database, but rather some smaller subset of the data that represents the information you want. |
|
|
|
|
|
|
|
|
This subset of database information (or recordset) is defined by a record source, which is just a set of criteria that you specify. For example, suppose you want to query the database for the authors whose last name is Smith. In this example, the data source is the BIBLIO database, and the record source is the query that returns the set of records containing all the Smiths. |
|
|
|
|
|
|
|
|
Anyway, the point of this discussion is to clarify what the ADO Data control represents to the rest of your program: a set of records resulting from a query against a database. |
|
|
|
|
|
|
|
|
For the ADO Data control to access data, it has to first be able to connect to a database. You must set up the ConnectionString property of the ADO Data control to provide the necessary information. You can do so at runtime or designtime. The General tab of the Property Pages, shown earlier in Figure 28.5, provides three methods of building the connection string: |
|
|
|
|
|